{layout name="layout"}
<div class="panel">
    <div class="panel-body">
        <div class="pad-btm form-inline">
            <div class="row">
                <div class="col-sm-6 table-toolbar-left">
                    <button class="btn btn-default" data-target="#projects-modal" data-toggle="modal"><i class="fa fa-plus-circle"></i> 添加</button>
                </div>
            </div>
            <div class="row">
            {if $projects}
            {foreach $projects as $project}
                <div class="col-sm-2 category-div">
                    <div class="panel text-center">
                        <img src="__IMG__/classify.png" width="79%" height="79%">
                        <div class="panel-heading bg-gray-light">
                            <h3 class="panel-title text-dark">{$project.classifyname}</h3>
                        </div>
                        <div class="panel-body" style="padding:2px;">
                            <div class="btn-group">
                                <ul class="list-unstyled">
                                    <li class="col-xs-4 text-2x">
                                        <a href='/api/projects/detail?pid={$project.id}'><button class="btn btn-default" title="查看详情" data-target="#detail-modal" data-toggle="modal" data-catid="{$project.id}">
                                            <i class="ion-document-text"></i>
                                        </button></a>
                                    </li>
                                    <li class="col-xs-4 text-2x">
                                        <button class="btn btn-default" title="编辑项目" data-target="#projects-modal" data-toggle="modal" data-catid="{$project.id}">
                                            <i class="fa fa-pencil-square-o"></i>
                                        </button>
                                    </li>
                                    <li class="col-xs-4 text-2x">
                                        <button class="btn btn-default" title="删除项目" onclick='del_project(this,"{$project.id}")'>
                                            <i class="ion-trash-b"></i>
                                        </button>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            {/foreach}
            {/if}
            </div>
        </div>
    </div>
</div>
{include file="modals/projects-modal"}
<script type="text/javascript">
    function del_project(e,catid){
        bootbox.setDefaults({locale:"zh_CN"});
        bootbox.confirm("确定删除吗", function(result) {
            if(result){
                $.ajax({
                    url:"{:url('api/projects/del_cat')}",
                    type:"post",
                    data:{"catid":catid},
                    dataType:"json",
                    success:function(result){
                        if(result.status == 'success'){
                            $.niftyNoty({
                                type: 'success',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                            $(e).parents('.category-div').detach();
                        }else{
                            $.niftyNoty({
                                type: 'warning',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                        }
                    },
                    error:function(){
                        $.niftyNoty({
                            type: 'danger',
                            icon : 'pli-exclamation icon-2x',
                            message : '网络连接失败',
                            container : 'floating',
                            timer : 1500,
                        });
                    }
                });
            }
        })
        
    }
</script>